package cn.bocweb.spinning.view.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bocweb.spinning.R;
import cn.bocweb.spinning.model.Bean.ForumReplyBean;
import cn.bocweb.spinning.view.common.GlideCircle;
import cn.bocweb.spinning.view.common.MyAdapter;
import cn.bocweb.spinning.view.common.SwipeListView;

/**
 * Created by chenchangxing on 15/12/21.
 */
public class ReplyMsgAdapter extends MyAdapter<ForumReplyBean.DataBean> implements View.OnClickListener {

    public ReplyMsgAdapter(Context context, List<ForumReplyBean.DataBean> list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_my_msg, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.btnResponseMsg.setOnClickListener(this);

        Glide
                .with(context)
                .load(list.get(position).getUthumb())
                .placeholder(R.mipmap.drawer_icon_unlogin)
                .transform(new GlideCircle(context))
                .into(holder.icon);

        holder.nickname.setText(list.get(position).getNickname());
        holder.position.setText(list.get(position).getFloor());

        List<ForumReplyBean.DataBean.ReplyBean> replyBeanList = list.get(position).getReply();
        ReplyAdapter replyAdapter = new ReplyAdapter(context, replyBeanList, list.get(position).getForumid());
        holder.replyList.setAdapter(replyAdapter);

        return convertView;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_response_msg: {
//                Intent intent = new Intent(context, Rep)
            }
        }
    }


    static class ViewHolder {
        @Bind(R.id.icon)
        ImageView icon;
        @Bind(R.id.nickname)
        TextView nickname;
        @Bind(R.id.position)
        TextView position;
        @Bind(R.id.reply_nickname)
        TextView replyNickname;
        @Bind(R.id.reply_content)
        TextView replyContent;
        @Bind(R.id.content)
        TextView content;
        @Bind(R.id.address)
        TextView address;
        @Bind(R.id.btn_response_msg)
        LinearLayout btnResponseMsg;
        @Bind(R.id.reply_list)
        SwipeListView replyList;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
